package com.franklin.ideaplugin.maphelper.beans.colmember;

import com.franklin.ideaplugin.api.utils.ClassUtils;
import com.franklin.ideaplugin.maphelper.resolver.AbstractColMemberResolverFactory;
import com.franklin.ideaplugin.maphelper.utils.FastJsonUtils;
import lombok.Data;

import java.util.Collection;
import java.util.Objects;

/**
 * @author Ye Junhui
 * @since 2024/3/21
 */
@Data
public class StringColMember implements IColMember {

    private String keyText;
    private String valueText;
    private String valueClass;
    private Object value;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StringColMember that = (StringColMember) o;
        return Objects.equals(keyText, that.keyText);
    }

    @Override
    public int hashCode() {
        return Objects.hash(keyText);
    }

    @Override
    public String getKeyText() {
        return this.keyText;
    }

    @Override
    public String getValueText() {
        return this.valueText;
    }

    @Override
    public String getValueClass() {
        return this.valueClass;
    }

    @Override
    public String getValueClassSimple() {
        return ClassUtils.getClassSimpleName(this.valueClass);
    }

    @Override
    public Collection<IColMember> getChildren(AbstractColMemberResolverFactory colMemberResolverFactory) {
        Object value = getValue();
        //目前仅支持fastjson别的框架有时间再做封装
        return FastJsonUtils.resolveJsonStringMembers(getValueClass(),value);
    }
}
